﻿@model System.Collections.Generic.IEnumerable<UserIdentityDemo.Models.Album>
@using System.Linq
@using System.Security.Claims
@using Microsoft.AspNetCore.Authorization
@using UserIdentityDemo
@inject IAuthorizationService AuthorizationService

@if (!User.Identities.Any(u => u.IsAuthenticated))
{
    <h1>Hello</h1>
    <p>@Html.ActionLink("Login", "Login", "Account")</p>
}
else
{
    <h1>Hello @User.FindFirst(ClaimTypes.Name).Value from @User.FindFirst(Constants.CompanyClaimType).Value</h1>
    <p>@Html.ActionLink("Logout", "Logout", "Account")</p>
}

<h1>Music Library</h1>
@foreach (var album in Model)
{
    <p>
        @Html.ActionLink(album.Title, "Details", new {id = album.Id}) by @album.Artist.
        @if (User.Identity.IsAuthenticated &&
             await AuthorizationService.AuthorizeAsync(User, album, PolicyNames.CanEditAlbum))
        {
            <text>&nbsp;| &nbsp;</text>
            @Html.ActionLink("Edit", "Edit", new {id = album.Id})
        }
        <br/>
        Published by @album.Publisher
    </p>
}